package com.atguigui.leetcode;

/**
 * 942.增减字符串匹配
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/5/9 9:09
 */
public class P942DiStringMatch {
    public static void main(String[] args) {
        Solution solution = new P942DiStringMatch().new Solution();
        // TO TEST
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int[] diStringMatch(String s) {
            int n = s.length(), lo = 0, hi = n;
            int[] perm = new int[n + 1];
            for (int i = 0; i < n; ++i) {
                perm[i] = s.charAt(i) == 'I' ? lo++ : hi--;
            }
            perm[n] = lo;
            return perm;
        }
    }
}
